<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">
    <h1>{{msg}}</h1>
    <!-- 修改基本数据类型 -->
    <p>{{count}}</p>
    <button @click="count++">修改数字</button>
    <!-- 修改数组类型 -->
    <ul>
      <li v-for="item of arr">{{item}}</li>
    </ul>
    <button @click="add">增加数组成员</button>
    <button @click="filter">数组过滤</button>
    <button @click="sort">数组排序</button>
    <!-- 修改对象类型 -->
    <ul>
      <li v-for="item in obj">{{item}}</li>
    </ul>
    <button @click="addAttr">增加对象属性</button>
    <button @click="deleteAttr">删除对象属性</button>
  </div>
  <script>
    Vue.config.productionTip = false;
    const vm = new Vue({
      el: "#app",
      data() {
        return {
          msg: "hello vue!",
          count: 0,
          arr: ['lucy', 'jan', 'popo'],
          obj: {
            name: "jon",
            age: 18
          }
        }
      },
      methods: {
        add() {
          this.arr.push('lulu')
        },
        filter() {
          this.arr = this.arr.filter(item => {
            return item !== 'popo'
          })
        },
        sort() {
          this.arr.sort()
        },
        addAttr() {
          //this.$set(this.obj,'sex','男')
          Vue.set(this.obj, 'sex', '男')
        },
        deleteAttr() {
          this.$delete(this.obj, 'age')
          //Vue.delete(this.obj, 'age')
        }
      }
    })
  </script>
</body>

</html>